import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_yd_simple/Project/SignOrder/WiatSignDetail.dart';

class WaitSignOrderPageDemo extends StatefulWidget {
  const WaitSignOrderPageDemo({super.key});

  @override
  State<WaitSignOrderPageDemo> createState() => _WaitSignOrderPageDemoState();
}

class _WaitSignOrderPageDemoState extends State<WaitSignOrderPageDemo> {
  var itemAry =[{"mailNo":"4001234567890","recStreet":"徐泾镇虹桥世界中心-D2","recName":"梁少爷","recTel":"18337100000","select":0},
                {"mailNo":"4001234567891","recStreet":"徐泾镇虹桥世界中心-D1","recName":"徐小姐","recTel":"18337100001","select":0},
                {"mailNo":"4001234567892","recStreet":"徐泾镇虹桥世界中心-D3","recName":"张大宝","recTel":"18337100002","select":0},
                {"mailNo":"4001234567893","recStreet":"徐泾镇虹桥世界中心-L2","recName":"王二狗","recTel":"18337100003","select":0},
                {"mailNo":"4001234567894","recStreet":"徐泾镇虹桥世界中心-L1","recName":"李老板","recTel":"18337100004","select":0},
                {"mailNo":"4001234567890","recStreet":"徐泾镇虹桥世界中心-D2","recName":"梁少爷","recTel":"18337100000","select":0},
                {"mailNo":"4001234567891","recStreet":"徐泾镇虹桥世界中心-D1","recName":"徐小姐","recTel":"18337100001","select":0},
                {"mailNo":"4001234567892","recStreet":"徐泾镇虹桥世界中心-D3","recName":"张大宝","recTel":"18337100002","select":0},
                {"mailNo":"4001234567893","recStreet":"徐泾镇虹桥世界中心-L2","recName":"王二狗","recTel":"18337100003","select":0},
                {"mailNo":"4001234567894","recStreet":"徐泾镇虹桥世界中心-L1","recName":"李老板","recTel":"18337100004","select":0},
                {"mailNo":"4001234567895","recStreet":"徐泾镇虹桥世界中心-L3","recName":"赵秘书","recTel":"18337100005","select":0}];
  
  late EasyRefreshController _controller;
  int _count = 10;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _controller = EasyRefreshController(
      controlFinishLoad: true,
      controlFinishRefresh: true,
    );
  }

  @override
  void dispose() {
    _controller.dispose();
    // TODO: implement dispose
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return EasyRefresh(
      controller: _controller,

      //下拉刷新
      onRefresh: () {
        Future.delayed(const Duration(milliseconds: 5));
        if(!mounted) {
          return;
        }

        setState(() {
          _count = 10;
        });

        _controller.finishRefresh();
        _controller.resetFooter();
      },

      //上拉加载
      onLoad: () async {
        await Future.delayed(const Duration(seconds: 1));
        if(!mounted) {
          return;
        }

        setState(() {
          _count += 5;
        });

        _controller.finishLoad(
          //_count >= 20 ? IndicatorResult.noMore : IndicatorResult.success
        );
        _controller.resetFooter();

      },

      child: ListView.builder(
      itemCount: itemAry.length,
      itemBuilder: (context, index) {
        return GestureDetector(
          onTap: () {
            Navigator.push(context, MaterialPageRoute(builder: (buildContex){
              return WiatSignDetailDemo();
            },settings: RouteSettings(arguments: '我是待签收界面来的')));
          },
          child: Container(
          color: Colors.white,
          margin: EdgeInsets.only(top: 8),
          child: Row(
            children: [
              IconButton(
                onPressed: () {
                  setState(() {
                    itemAry[index]["select"] = itemAry[index]["select"]==1?0:1;
                  });
                },
                icon: Image.asset(itemAry[index]["select"]==1?'lib/Project/Images/Sign/sign_icon_select.png':'lib/Project/Images/Sign/sign_icon_normal.png',width: 23,height: 23)),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  SizedBox(height: 12),
                  SizedBox(
                    height:24,
                    child:Text((itemAry[index]["recName"] as String) +"  "+ (itemAry[index]["recTel"] as String),style: TextStyle(fontSize: 14,color: Color(0xFF222222),fontWeight: FontWeight.w500)),
                  ),
                  SizedBox(
                    height:20,
                    child:Text(itemAry[index]["mailNo"] as String,style: TextStyle(fontSize: 14,color: Color(0xFF222222),fontWeight: FontWeight.w500)),
                  ),
                  Text(itemAry[index]["recStreet"] as String,style: TextStyle(fontSize: 14,color: Color(0xFF666666))),
                  SizedBox(height: 6),
                ],
              )
            ],
          ),
        )
        );
      },
    )
  

    );

    
  
  }
}